<template>
  <div style="height: 50px;width: 100%; line-height: 50px;border-bottom: 1px solid #ccc;display: flex">
    <div style="width: 200px;padding-left: 20px;font-weight: bold;color: white;font-size: 19px;">健身会所管理系统</div>
    <div style="font-weight: bold;color: #611ee3;flex: 1;font-size: 19px;">欢迎进入本系统
      <span style="float: right;margin-right: 150px;">{{ nowDate }}</span></div>
    <div style="width: 500px;">
<!--      <img src="../assets/img.png" style="width: 8%;margin-top: 10px"/>&nbsp;&nbsp;-->
        <el-dropdown style="margin-top: -15px">
          <span class="el-dropdown-link" style="color:white;font-size: 19px;">用户名：{{user.username}}
<!--        <i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>-->
          </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <span class="el-dropdown-link" style="color:white;font-size: 19px;">
         用户角色： {{role}}
          </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <a @click="$router.push('/login')" style="color:white;font-size: 19px;float:right;font-weight: 500;opacity: 0.8;text-decoration: underline">退出系统</a>
<!--          <template #dropdown>-->
<!--            <el-dropdown-menu>-->
<!--&lt;!&ndash;              <el-dropdown-item @click="$router.push('/person')">个人信息</el-dropdown-item>&ndash;&gt;-->
<!--              <el-dropdown-item >退出系统</el-dropdown-item>-->
<!--            </el-dropdown-menu>-->
<!--          </template>-->
      </el-dropdown>
    </div>
  </div>
</template>

<script>
export default {
  name: "Header",
  data(){
    return{
      user:{},
      nowDate: "", // 当前日期
      role:""
    }
  },
  created() {
    let str = sessionStorage.getItem("user") || "{}";
    this.user = JSON.parse(str);
    this.currentTime();
    if (this.user.role===1){
      this.role="管理员"
    }else if (this.user.role===2){
      this.role="会员"
    }else if (this.user.role===3){
      this.role="教练"
    }
  },
  methods:{
    currentTime() {
      setInterval(this.formatDate, 500);
    },
    formatDate() {
      let date = new Date();
      let year = date.getFullYear(); // 年
      let month = date.getMonth() + 1; // 月
      let day = date.getDate(); // 日
      let week = date.getDay(); // 星期
      let weekArr = [ "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" ];
      let hour = date.getHours(); // 时
      hour = hour < 10 ? "0" + hour : hour; // 如果只有一位，则前面补零
      let minute = date.getMinutes(); // 分
      minute = minute < 10 ? "0" + minute : minute; // 如果只有一位，则前面补零
      let second = date.getSeconds(); // 秒
      second = second < 10 ? "0" + second : second; // 如果只有一位，则前面补零
      this.nowDate = `${year}/${month}/${day} ${hour}:${minute}:${second} ${weekArr[week]}`;
    }
  }
}
</script>

<style scoped>
  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
</style>
